package Solution151_175;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class Solution168excel {
    public String convertToTitle(int n) {
        String[] keys = new String[]{
                "A", "B", "C", "D", "E", "F", "G",
                "H", "I", "J", "K", "L", "M", "N",
                "O", "p", "Q", "R", "S", "T", "W",
                "V", "W", "X", "Y", "Z"};
        List<String> list=new ArrayList<>();

        while (n>0) {
            n--;
            list.add(keys[n%26]);
            n = n/26;
            if(n==0){
                break;
            }
        }

        StringBuilder builder = new StringBuilder();
        for(int i=list.size()-1;i>=0;i--){
            builder.append(list.get(i));
        }
        return builder.toString();
    }

    @Test
    public void test() {

        System.out.println(convertToTitle(701));
        System.out.println(convertToTitle(702));
        System.out.println(convertToTitle(28));
    }
}
